<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xml:lang="en" lang="en">
	<h:head />
	<body>
		<ui:composition template="/rootWeb.xhtml">
	    <ui:define name="header">
	        <title>基础数据明细列表</title>
			<script type="text/javascript">
				//页面载入时注册
	        	jQuery(document).ready(function(){
	        		//鼠标移入
					jQuery("#dicItemListTable_data tr").live("mouseover", function() {
					  	jQuery(this).css("background-color","#CCCCCC");
					});
					//鼠标移出
					jQuery("#dicItemListTable_data tr").live("mouseout", function() {
					  	jQuery(this).css("background-color","white");
					});
				});
				//保存结束后调用
				function handleSaveDictionaryItem(xhr, status, args) {
					if(args.error){
						alert(args.error);
					}else{
						addDictionaryItemDlg.hide();
						alert(args.msg);
					}
				}
				//设置基础数据类型
				function handleSetDictionaryType(xhr, status, args) {
					if(args.selectedNull){
						alert(args.selectedNull);
						return ;
					}
					selectDictionaryTypeDlg.hide();
				}
				//更新结束后调用 
				function handleUpdateDictionaryItem(xhr, status, args) {
					if(args.error){
						alert(args.error);
					}else{
						updateDictionaryItemDlg.hide();
						alert(args.msg);
					}
				}
				function resetQueryCondition(){
					jQuery("#queryCode").val('');
					jQuery("#queryName").val('');
					jQuery("#queryTypeID").val('');
					jQuery("#queryTypeCode").val('');
				}
			</script>
	    </ui:define>
	    <ui:define name="body">
	    	<h:form id="form" prependId="false">
		    	<h:panelGrid id="queryGrid" columns="11">
		    		<h:outputLabel for="queryTypeCode" value="数据类型："/>
		    		<h:inputHidden id="queryTypeID" value="#{dictionaryItemAction.queryDicItem.dicType.typeID}" />
		    		<p:inputText id="queryTypeCode" value="#{dictionaryItemAction.queryDicItem.dicType.typeName}" readonly="true"/>
		    		<p:commandButton  value="选择" action="#{dictionaryItemAction.queryDictionaryType('query')}" 
							oncomplete="selectDictionaryTypeDlg.show();" update=":form:typeTable"/>
		    		<h:outputLabel for="queryCode" value="数据代码："/>
		    		<p:inputText id="queryCode" value="#{dictionaryItemAction.queryDicItem.itemCode}"/>
		    		<h:outputLabel for="queryName" value="数据名称："/>
		    		<p:inputText id="queryName" value="#{dictionaryItemAction.queryDicItem.itemName}"/>
		    		<p:commandButton value="查询" action="#{dictionaryItemAction.queryResultBycondition}" update=":form:dicItemListTable"  icon="ui-icon-search"/>
		    		<p:commandButton value="重置" onclick="resetQueryCondition();"/>
		    		<p:commandButton value="新增" action="#{dictionaryItemAction.addDictionaryItem}"  update=":form:addDictionaryItemDlgID" oncomplete="addDictionaryItemDlg.show();"/>
		    	</h:panelGrid> <p/>
		    	<p:dataTable id="dicItemListTable" value="#{dictionaryItemAction.dicItemList}" var="dicItem" rowKey="dicItem" emptyMessage="没有记录！"
		    			paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
                 		paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  >
	    			<p:column headerText="数据类型">#{dicItem.dicType.typeName}</p:column>
	    			<p:column headerText="数据名称">#{dicItem.itemName}</p:column>
	    			<p:column headerText="数据代码">#{dicItem.itemCode}</p:column>
	    			<p:column headerText="数据描述">#{dicItem.itemDesc}</p:column>
	    			<p:column headerText="是否可用">
			            <h:outputText value="可用" rendered="#{dicItem.itemAvailable eq '0'}"/>
			            <h:outputText value="不可用" rendered="#{dicItem.itemAvailable eq '1'}"/>
	    			</p:column>
	    			<p:column headerText="操作">
	    				<p:commandLink value="修改" action="#{dictionaryItemAction.setUpdateDicItem(dicItem)}" style="color:RED" update=":form:updateDictionaryItemDlgID"
	    					oncomplete="updateDictionaryItemDlg.show()" rendered="#{dicItem.dicType.typeCode ne 'MoldState' }">
	    				</p:commandLink>
					</p:column>
	    		</p:dataTable>
	    		
	    		<p:dialog id="updateDictionaryItemDlgID" header="修改数据明细" widgetVar="updateDictionaryItemDlg" modal="true" 
					resizable="false">
					<h:panelGrid columns="3" cellpadding="5">
						<h:outputLabel for="itemName_update" value="名称:" />
						<p:inputText value="#{dictionaryItemAction.updateDicItem.itemName}" id="itemName_update"  maxlength="100"/>
						<p:spacer/>
						<h:outputLabel for="itemCode_update" value="代码:" />
						<p:inputText value="#{dictionaryItemAction.updateDicItem.itemCode}" id="itemCode_update" maxlength="50"/>
						<p:spacer/>
			            <h:outputLabel for="itemDesc_update" value="描述:" />
						<p:inputTextarea value="#{dictionaryItemAction.updateDicItem.itemDesc}" id="itemDesc_update"  maxlength="250"/>
						<p:spacer/>
			            <h:outputLabel for="itemType_update" value="数据类型:"  />
						<p:inputText value="#{dictionaryItemAction.updateDicItem.dicType.typeName}" id="itemType_update"  readonly="true"/>
						<p:commandLink  value="选择" action="#{dictionaryItemAction.queryDictionaryType('update')}" 
							style="color:RED"
							oncomplete="selectDictionaryTypeDlg.show();"
							update=":form:typeTable"/>
						<h:outputLabel for="itemAvailable_update" value="是否可用:" />
						 <h:selectOneMenu id="itemAvailable_update" value="#{dictionaryItemAction.updateDicItem.itemAvailable}" >  
			                <f:selectItems value="#{dictionaryItemAction.availableItems}"/>
			            </h:selectOneMenu>  
			            <p:spacer/>
						<f:facet name="footer">
							<p:commandButton id="updateItemBtn" value="更新" update="dicItemListTable"
								actionListener="#{dictionaryItemAction.updateDicItem}"
								oncomplete="handleUpdateDictionaryItem(xhr, status, args)" />
						</f:facet>
					</h:panelGrid>
				</p:dialog>
	    		
				<p:dialog id="addDictionaryItemDlgID" header="增加数据明细" widgetVar="addDictionaryItemDlg" modal="true" 
					resizable="false">
					<h:panelGrid columns="3" cellpadding="5">
						<h:outputLabel for="itemName" value="名称:" />
						<p:inputText value="#{dictionaryItemAction.saveDicItem.itemName}" id="itemName"  maxlength="100"/>
						<p:spacer/>
						<h:outputLabel for="itemCode" value="代码:" />
						<p:inputText value="#{dictionaryItemAction.saveDicItem.itemCode}" id="itemCode" maxlength="50"/>
						<p:spacer/>
			            <h:outputLabel for="itemDesc" value="描述:" />
						<p:inputTextarea value="#{dictionaryItemAction.saveDicItem.itemDesc}" id="itemDesc"  maxlength="250"/>
						<p:spacer/>
			            <h:outputLabel for="itemType" value="数据类型:"  />
						<p:inputText value="#{dictionaryItemAction.saveDicItem.dicType.typeName}" id="itemType"  readonly="true"/>
						<p:commandLink  value="选择" action="#{dictionaryItemAction.queryDictionaryType('add')}" 
							style="color:RED"
							oncomplete="selectDictionaryTypeDlg.show();"
							update=":form:typeTable"/>
						<h:outputLabel for="itemAvailable" value="是否可用:" />
						 <h:selectOneMenu id="itemAvailable" value="#{dictionaryItemAction.saveDicItem.itemAvailable}" >  
			                <f:selectItems value="#{dictionaryItemAction.availableItems}"/>
			            </h:selectOneMenu>  
			            <p:spacer/>
						<f:facet name="footer">
							<p:commandButton id="saveItemBtn" value="保存" update="dicItemListTable"
								actionListener="#{dictionaryItemAction.saveDictionaryItem}"
								oncomplete="handleSaveDictionaryItem(xhr, status, args)" />
						</f:facet>
					</h:panelGrid>
				</p:dialog>
				
				<p:dialog id="selectDictionaryTypeDlgID" header="选择数据类型" widgetVar="selectDictionaryTypeDlg" modal="true"  resizable="false">
					<h:panelGrid  columns="2" cellpadding="5">
						<p:dataTable id="typeTable" value="#{dictionaryItemAction.dicTypeList}" var="dicType" rowKey="#{dicType}" emptyMessage="没有记录！"
								selection="#{dictionaryItemAction.selectedDicType}"
				    			paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="true" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
		                 		paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  >
		                 	<p:column selectionMode="single" ></p:column>
			    			<p:column headerText="类型名称">#{dicType.typeName}</p:column>
			    			<p:column headerText="类型代码">#{dicType.typeCode}</p:column>
			    			<p:column headerText="类型描述">#{dicType.typeDesc}</p:column>
			    			<p:column headerText="是否可用">
			    				<h:selectOneMenu value="#{dicType.available}" disabled="true">
					                <f:selectItems value="#{dictionaryAction.availableItems}"/>
					            </h:selectOneMenu>
			    			</p:column>
			    		</p:dataTable>
			    		<f:facet name="footer">
			    				<p:commandButton value="确定" action="#{dictionaryItemAction.setDictionaryType}" oncomplete="handleSetDictionaryType(xhr, status, args)"
			    					update=":form:itemType_update,:form:itemType,:form:queryTypeID,:form:queryTypeCode"/>
			    		</f:facet>
					</h:panelGrid>
				</p:dialog>
			</h:form>
			
	    </ui:define>
	</ui:composition>
	</body>
</html>
